<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of hesschek</title>
  <meta name="keywords" content="hesschek">
  <meta name="description" content="HESSCHEK Use central differences to confirm correct evaluation of Hessian matrix.">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2003 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../../menu.html">Home</a> &gt;  <a href="#">ReBEL-0.2.7</a> &gt; <a href="#">netlab</a> &gt; hesschek.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../../menu.html"><img alt="<" border="0" src="../../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="menu.html">Index for .\ReBEL-0.2.7\netlab&nbsp;<img alt=">" border="0" src="../../right.png"></a></td></tr></table>-->

<h1>hesschek
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>HESSCHEK Use central differences to confirm correct evaluation of Hessian matrix.</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>function h = hesschek(net, x, t) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre class="comment">HESSCHEK Use central differences to confirm correct evaluation of Hessian matrix.

    Description

    HESSCHEK(NET, X, T) takes a network data structure NET, together with
    input and target data matrices X and T, and compares the evaluation
    of the Hessian matrix using the function NETHESS and using central
    differences with the function NETERR.

    The optional return value H is the Hessian computed using NETHESS.

    See also
    <a href="nethess.html" class="code" title="function [h, varargout] = nethess(w, net, x, t, varargin)">NETHESS</a>, <a href="neterr.html" class="code" title="function [e, varargout] = neterr(w, net, x, t)">NETERR</a></pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="neterr.html" class="code" title="function [e, varargout] = neterr(w, net, x, t)">neterr</a>	NETERR	Evaluate network error function for generic optimizers</li><li><a href="nethess.html" class="code" title="function [h, varargout] = nethess(w, net, x, t, varargin)">nethess</a>	NETHESS Evaluate network Hessian</li><li><a href="netpak.html" class="code" title="function w = netpak(net)">netpak</a>	NETPAK	Combines weights and biases into one weights vector.</li></ul>
This function is called by:
<ul style="list-style-image:url(../../matlabicon.gif)">
</ul>
<!-- crossreference -->


<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function h = hesschek(net, x, t)</a>
0002 <span class="comment">%HESSCHEK Use central differences to confirm correct evaluation of Hessian matrix.</span>
0003 <span class="comment">%</span>
0004 <span class="comment">%    Description</span>
0005 <span class="comment">%</span>
0006 <span class="comment">%    HESSCHEK(NET, X, T) takes a network data structure NET, together with</span>
0007 <span class="comment">%    input and target data matrices X and T, and compares the evaluation</span>
0008 <span class="comment">%    of the Hessian matrix using the function NETHESS and using central</span>
0009 <span class="comment">%    differences with the function NETERR.</span>
0010 <span class="comment">%</span>
0011 <span class="comment">%    The optional return value H is the Hessian computed using NETHESS.</span>
0012 <span class="comment">%</span>
0013 <span class="comment">%    See also</span>
0014 <span class="comment">%    NETHESS, NETERR</span>
0015 <span class="comment">%</span>
0016 
0017 <span class="comment">%    Copyright (c) Ian T Nabney (1996-2001)</span>
0018 
0019 w0 = <a href="netpak.html" class="code" title="function w = netpak(net)">netpak</a>(net);
0020 nwts = length(w0);
0021 h = <a href="nethess.html" class="code" title="function [h, varargout] = nethess(w, net, x, t, varargin)">nethess</a>(w0, net, x, t);
0022 
0023 w = w0;
0024 hcent = zeros(nwts, nwts);
0025 h1 =  0.0; h2 =  0.0; h3 =  0.0; h4 = 0.0;
0026 epsilon = 1.0e-4;
0027 fprintf(1, <span class="string">'Checking Hessian ...\n\n'</span>);
0028 <span class="keyword">for</span> k = 1:nwts;
0029   <span class="keyword">for</span> l = 1:nwts;
0030     <span class="keyword">if</span>(l == k)
0031       w(k) = w0(k) + 2.0*epsilon;
0032       h1 = <a href="neterr.html" class="code" title="function [e, varargout] = neterr(w, net, x, t)">neterr</a>(w, net, x, t);
0033       w(k) = w0(k) - 2.0*epsilon;
0034       h2 = <a href="neterr.html" class="code" title="function [e, varargout] = neterr(w, net, x, t)">neterr</a>(w, net, x, t);
0035       w(k) = w0(k);
0036       h3 = <a href="neterr.html" class="code" title="function [e, varargout] = neterr(w, net, x, t)">neterr</a>(w, net, x, t);
0037       hcent(k, k) = (h1 + h2 - 2.0*h3)/(4.0*epsilon^2);
0038     <span class="keyword">else</span>
0039       w(k) = w0(k) + epsilon;
0040       w(l) = w0(l) + epsilon;
0041       h1 = <a href="neterr.html" class="code" title="function [e, varargout] = neterr(w, net, x, t)">neterr</a>(w, net, x, t);
0042       w(k) = w0(k) - epsilon;
0043       w(l) = w0(l) - epsilon;
0044       h2 = <a href="neterr.html" class="code" title="function [e, varargout] = neterr(w, net, x, t)">neterr</a>(w, net, x, t);
0045       w(k) = w0(k) + epsilon;
0046       w(l) = w0(l) - epsilon;
0047       h3 = <a href="neterr.html" class="code" title="function [e, varargout] = neterr(w, net, x, t)">neterr</a>(w, net, x, t);
0048       w(k) = w0(k) - epsilon;
0049       w(l) = w0(l) + epsilon;
0050       h4 = <a href="neterr.html" class="code" title="function [e, varargout] = neterr(w, net, x, t)">neterr</a>(w, net, x, t);
0051       hcent(k, l) = (h1 + h2 - h3 - h4)/(4.0*epsilon^2);
0052       w(k) = w0(k);
0053       w(l) = w0(l);
0054     <span class="keyword">end</span>
0055   <span class="keyword">end</span>
0056 <span class="keyword">end</span>
0057 
0058 fprintf(1, <span class="string">'   analytical    numerical       delta\n\n'</span>);
0059 temp = [h(:), hcent(:), (h(:) - hcent(:))];
0060 fprintf(1, <span class="string">'%12.6f  %12.6f  %12.6f\n'</span>, temp');</pre></div>
<hr><address>Generated on Tue 26-Sep-2006 10:36:21 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> &copy; 2003</address>
</body>
</html>